package org.jeecg.trace.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.trace.entity.MesMaterialLot;
import org.jeecg.trace.mapper.MesMaterialLotHistoryMapper;
import org.jeecg.trace.mapper.MesMaterialLotMapper;
import org.jeecg.trace.service.IMesMaterialLotService;
import org.jeecg.common.api.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

/**
 * @Description: 物料批次表
 * @Author: shaolong
 * @Date:   2022-10-26
 * @Version: V1.0
 */
@Service
public class MesMaterialLotServiceImpl extends ServiceImpl<MesMaterialLotMapper, MesMaterialLot> implements IMesMaterialLotService {

	@Autowired
	private MesMaterialLotMapper mesMaterialLotMapper;
	@Autowired
	private MesMaterialLotHistoryMapper mesMaterialLotHistoryMapper;

	@Override
	@Transactional(rollbackFor = Exception.class)
	public void delMain(String id) {
		//把这里的删除给改了 改成按照id删
        Map<String, Object> map = new HashMap<>();
        map.put("REC_ID",id);
        mesMaterialLotMapper.deleteByMap(map);
	}

	@Override
	@Transactional(rollbackFor = Exception.class)
	public void delBatchMain(Collection<? extends Serializable> idList) {
		for(Serializable id:idList) {
			mesMaterialLotMapper.deleteById(id);
        }
    }

    @Override
    public Result<String> edit(MesMaterialLot mesMaterialLot) {
        LambdaUpdateWrapper<MesMaterialLot> eq = new LambdaUpdateWrapper<MesMaterialLot>();
        //自定义更新条件   .eq(MesLineCfg::getLine, mesLineCfg.getLine());
        boolean update = update(mesMaterialLot, eq);
        return update ? Result.ok("修改成功!") : Result.error("修改失败!");
    }

    @Override
    public IPage<MesMaterialLot> pageList(Page<MesMaterialLot> page, MesMaterialLot mesMaterialLot) {
        return this.baseMapper.pageList(page, mesMaterialLot);
    }
}
